//
//  ClassifyHeaderView.m
//  LiteraryTune
//
//  Created by xingyi on 2018/11/27.
//  Copyright © 2018 cxd. All rights reserved.
//

#import "ClassifyHeaderView.h"

@implementation ClassifyHeaderView
{
    UIView *_topLine;
    UILabel *_titleLabel;
    UIButton *_moreBtn;
}

- (void)setClassifyTitle:(NSString *)classifyTitle {
    
    _classifyTitle = classifyTitle;
    _titleLabel.text = classifyTitle;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.equalTo(@5);
    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_topLine.mas_bottom);
        make.bottom.equalTo(self.mas_bottom);
        make.left.equalTo(self.mas_left).offset(15);
        make.width.equalTo(@200);
    }];
    
    [_moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_topLine.mas_bottom);
        make.bottom.equalTo(self.mas_bottom);
        make.right.equalTo(self.mas_right).offset(-15);
    }];
    
}

- (void)setupUI {
    
    self.backgroundColor = [UIColor whiteColor];
    
    _topLine = [[UIView alloc] init];
    _topLine.backgroundColor = RGB(238, 238, 238);
    [self addSubview:_topLine];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.textColor = [UIColor colorFromHexCode:@"#666666"];
    _titleLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:_titleLabel];
    
    _moreBtn = [[UIButton alloc] init];
    _moreBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [_moreBtn setTitle:@"更多 >" forState:UIControlStateNormal];
    [_moreBtn setTitleColor:_titleLabel.textColor forState:UIControlStateNormal];
    [_moreBtn addTarget:self action:@selector(moreBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_moreBtn];
}

- (void)moreBtnDidClick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(classifyHeaderView:moreBtnDidClick:atSection:)]) {
        [self.delegate classifyHeaderView:self moreBtnDidClick:sender atSection:self.section];
    }
}

@end
